package com.graduation.check.dto;

import lombok.Data;
import java.time.LocalDateTime;

@Data
public class LoginResponse {
    private Integer code;
    private String message;
    private String token;
    private Long expiresIn;
    private UserInfo userInfo;

    @Data
    public static class UserInfo {
        private Long id;
        private String account;
        private String name;
        private String userType; // "S" 或 "T"
        private LocalDateTime createTime;
    }

    // 成功响应（用于登录）
    public static LoginResponse success(String message, String token, Long expiresIn, UserInfo userInfo) {
        LoginResponse response = new LoginResponse();
        response.setCode(200);
        response.setMessage(message);
        response.setToken(token);
        response.setExpiresIn(expiresIn);
        response.setUserInfo(userInfo);
        return response;
    }

    // 成功响应（用于注册）
    public static LoginResponse success(Integer code, String message, String token, Long expiresIn, UserInfo userInfo) {
        LoginResponse response = new LoginResponse();
        response.setCode(code);
        response.setMessage(message);
        response.setToken(token);
        response.setExpiresIn(expiresIn);
        response.setUserInfo(userInfo);
        return response;
    }

    // 错误响应
    public static LoginResponse error(Integer code, String message) {
        LoginResponse response = new LoginResponse();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    // 创建用户信息
    public static UserInfo createUserInfo(Long id, String account, String name, String userType, LocalDateTime createTime) {
        UserInfo userInfo = new UserInfo();
        userInfo.setId(id);
        userInfo.setAccount(account);
        userInfo.setName(name);
        userInfo.setUserType(userType);
        userInfo.setCreateTime(createTime);
        return userInfo;
    }
}